package com.billionsfinance.hessian.db;

/**
 * @fileName: ConfigDataSource.java
 * @author: WeiHui.Zhang
 * @date: 2016-10-11  14:38
 * @version: v1.0.0
 */
public enum ConfigDataSource {

	MYSQL("show tables like '%s'", "CREATE TABLE HESSIAN_SERVER (\n" +
			"  APP_CODE           VARCHAR(20)  NOT NULL,\n" +
			"  ACCESS_PATH        VARCHAR(100) NOT NULL,\n" +
			"  ACCESS_TYPE        VARCHAR(5)   NULL     DEFAULT NULL,\n" +
			"  INTERFACE_NAME     VARCHAR(200) NULL     DEFAULT NULL,\n" +
			"  SERVICE_CLASS_NAME VARCHAR(200) NULL     DEFAULT NULL,\n" +
			"  FUNCTION_DESC      VARCHAR(500) NULL     DEFAULT NULL,\n" +
			"  CREATED_TIME       DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
			"  CREATED_BY         VARCHAR(18)  NULL     DEFAULT NULL,\n" +
			"  UPDATED_TIME       DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
			"  UPDATED_BY         VARCHAR(18)  NULL     DEFAULT NULL\n" +
			") ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE utf8_bin;",
			"drop table if exists HESSIAN_SERVER;",
			"CREATE TABLE HESSIAN_CLIENT (\n" +
					"  APP_CODE       VARCHAR(20)  NOT NULL,\n" +
					"  INTERFACE_NAME VARCHAR(200) NOT NULL,\n" +
					"  GROUP_NO       VARCHAR(20)  NOT NULL,\n" +
					"  ACCESS_URL     VARCHAR(500) NULL     DEFAULT NULL,\n" +
					"  CONN_TIMEOUT   INT(11)      NULL     DEFAULT NULL,\n" +
					"  READ_TIMEOUT   INT(11)      NULL     DEFAULT NULL,\n" +
					"  USE_DESC       VARCHAR(500) NULL     DEFAULT NULL,\n" +
					"  CREATED_TIME   DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
					"  CREATED_BY     VARCHAR(18)  NULL     DEFAULT NULL,\n" +
					"  UPDATED_TIME   DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" +
					"  UPDATED_BY     VARCHAR(30)  NULL     DEFAULT NULL\n" +
					") ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE utf8_bin;",
			"drop table if exists HESSIAN_CLIENT;"),

	ORACLE("show tables like '%s'", "", "", "", "");

	private final String tablesSql;

	private final String serverCreateSql;

	private final String serverDropSql;

	private final String clientCreateSql;

	private final String clientDropSql;

	ConfigDataSource(String tablesSql, String serverCreateSql, String serverDropSql, String clientCreateSql, String clientDropSql) {
		this.tablesSql = tablesSql;
		this.serverCreateSql = serverCreateSql;
		this.serverDropSql = serverDropSql;
		this.clientCreateSql = clientCreateSql;
		this.clientDropSql = clientDropSql;
	}

	public String getTablesSql() {
		return tablesSql;
	}

	public String getServerCreateSql() {
		return serverCreateSql;
	}

	public String getServerDropSql() {
		return serverDropSql;
	}

	public String getClientCreateSql() {
		return clientCreateSql;
	}

	public String getClientDropSql() {
		return clientDropSql;
	}

	/**
	 * 获取相应数据库类型的枚举
	 *
	 * @param databaseType 数据库类型
	 * @return
	 */
	public static ConfigDataSource getDatabaseType(String databaseType) {
		if (null != databaseType) {
			for (ConfigDataSource configDataSource : ConfigDataSource.values()) {
				if (configDataSource.name().equalsIgnoreCase(databaseType.trim())) {
					return configDataSource;
				}
			}
		}
		return null;
	}
}
